Component({
  properties: {},
  data: {
    softOther: false,
    other: [],
    num: 1,
    useTotal: 0,//默认不使用佣金
    numOther: 1
  },
  lifetimes: {
    attached: function () {
    },
    moved: function () {
    },
    detached: function () {
    },
  },
  attached() {
  }, // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready: function () {
  },
  methods: {
    // 商品数量加
    add: function (e) {
      // 商品服务
      let other = this.data.other;
      let index = e.currentTarget.dataset.index;
      var id = e.target.dataset.id;
      var num = other[index].numberSelected;
      console.log(num);

      num++;
      var obj = {};
      obj['num' + index] = (num);

      other = [...other.slice(0, index), Object.assign({}, other[index], { numberSelected: (num) }), ...other.slice(index + 1)];
      console.log(other)
      this.setData({
        other: other,
      });
      post({
        path: "/order/updateCartShopNum",
        data: {
          skey: lsGetStr('skey'),
          id: this.data.other[index].cartId,
          number: num,
        }
      }).then(function (res) {

        // fnSuccess("修改成功")
      })
      this.calculateTotal();

    },
// 商品数量减
    cut: function (v) {

      // 商品服务
      let that = this;
      let other = this.data.other;
      let index = v.currentTarget.dataset.index;
      var num = other[index].numberSelected;

      if (num > 0) {
        num--;
      }

      post({
        path: "/order/updateCartShopNum",
        data: {
          skey: lsGetStr('skey'),
          id: that.data.other[index].cartId,
          number: num
        }
      }).then(function (res) {
      })

      if (num < 1) {
        post({
          path: "/order/removeShoppingcart",
          data: {
            skey: lsGetStr('skey'),
            id: that.data.other[index].cartId
          }
        }).then(function (res) {
          that.onLoad(that.options);
        })

      }
      var obj = {};
      obj['num' + index] = (num);

      other = [...other.slice(0, index), Object.assign({}, other[index], { numberSelected: (num) }), ...other.slice(index + 1)];
      this.setData({
        other: other,
      });
      this.calculateTotal();
    },
    // 服务加
    adds: function () {
      var numOther = this.data.numOther;
      numOther++;
      this.data.numOther = numOther;
      this.setData({
        numOther: numOther
      })
      this.calculateTotal();

    },
    // 服务减
    cuts: function () {

      var numOther = this.data.numOther;
      if (numOther <= 1) {
        if (numOther == 1) {
          return fnFail('代码文档和源码最少要选择一个');
        }
        return
      } else {
        numOther--;
        this.data.numOther = numOther;
      }
      this.setData({
        numOther: numOther
      })
      this.calculateTotal();
    },
    //输入佣金
    inputNum(e) { 
      let key = e.currentTarget.dataset.name,
        current = parseInt(e.detail.value),
        total = parseInt(this.data.user.pointsNow);
      if (current > total) {
        current = total;
      }
      this.setData({
        [key]: current
      })
    },
  },

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show: function () {

    },
  },
})